<?php
namespace Admin\Controller;
use Think\Controller;
class UserController extends Controller {
	
	//会员首页
    public function index(){
    	//实例化数据库
    	$model = M('user');
    	//查询总数据
    	$total = $model->count();
    	
    	//实例化分页
    	$page = new \Think\Page($total,1);
    	
    	//获取当前页
    	$p = isset($_GET['p'])?$_GET['p']:1;
    	
    	$this->data = $model->order('id desc')->page($p.',1')->select();
    	
    	//分页
    	$this->page = $page->show();
    	$this->total = $total;
    	$this->display();
    }
    
    //重置密码
    public function reset($id){
    	$model = M('User');
    	
    	$data[id] = $id;
    	$data[pass] = md5('123');
    	
    	if($model->save($data)){
    		$this->success("重置成功");
    	}else{
    		$this->error("重置失败");
    	}
    }
    
    //ajax获取用户基本信息
    public function ajax_user_info(){
    	$id = $_POST['id'];
    	
    	$this->data = M('userinfo')->where("uid=$id")->find();
    	if($this->data){
    		echo $this->fetch();
    	}else{
    		echo 0;
    	}
    	
    }
}